package cn.itcast;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class FreeMarkerDemo {
    public static void main(String[] args) throws Exception {
        //1. 创建Freemarker的配置对象Configuration
        Configuration configuration = new Configuration(Configuration.getVersion());

        //2. 设置模板加载路径, 字符集
        configuration.setDirectoryForTemplateLoading(new File("D:\\develop\\workspace\\itcast_health\\freemarker\\src\\main\\resources\\ftl"));
        configuration.setDefaultEncoding("utf-8");

        //3. 获取模板对象Template
        Template template = configuration.getTemplate("abc.ftl");

        //4. 组装数据模型 ---> Map
        Map map = new HashMap();
        map.put("swf666","真不戳");
        //5. 输入文件
        FileWriter writer = new FileWriter(new File("D:\\develop\\workspace\\itcast_health\\freemarker\\src\\main\\webapp\\abc.html"));
        template.process(map,writer);
    }
}
